package com.example.designpattern.structural.decorator.io;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

public class ReadFile {
    public static void main(String[] args) {
        ReadFile readFile = new ReadFile();
        try {
            readFile.io();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public void io() throws IOException {
        // inputStream/outputStream 的类结构即是装饰器模式
        // 这里的写法即为循环装饰的写法
        try (InputStream in = new BufferedInputStream(new FileInputStream("src/main/resources/blank.txt"))) {
            byte[] buffer = new byte[1024];
            while (in.read(buffer) != -1) {
                System.out.println(new String(buffer));
            }
        }
    }

}
